//
//  ShaituViewController.m
//  Xiangmu
//
//  Created by 이경인 on 2017/10/23.
//  Copyright © 2017年 LIJINGREN. All rights reserved.
//


#import "ShaituViewController.h"
#import "AFNetworking.h"
#import "UIImageView+WebCache.h"
#import "shaituTableViewCell.h"
#import "FabuViewController.h"
#import "PinglunViewController.h"
//#import "pinglunlbViewController.h"
@interface ShaituViewController ()<UITableViewDelegate,UITableViewDataSource>{
    
    NSArray *dateArr;
    UITableView *tableview;
 
}

@end

@implementation ShaituViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"SUPERSTAR";
    
    UIBarButtonItem *fabu = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"fabu.jpg"] style:UIBarButtonItemStyleDone target:self action:@selector(fabu)];
    self.navigationItem.rightBarButtonItem = fabu;
    
    dateArr = [NSArray array];
    tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height) style: UITableViewStylePlain];
    tableview.delegate=self;
    tableview.dataSource=self;
    tableview.sectionFooterHeight =100;
   
    
    [self.view addSubview:tableview];
    
    [self initwithdate];
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *str = @"shaituTableViewCell";
    shaituTableViewCell *cell = [tableview dequeueReusableCellWithIdentifier:str];
    if (cell==nil) {
        cell = [[[NSBundle mainBundle]loadNibNamed:str owner:self options:nil]lastObject];
        NSDictionary *dict =dateArr[indexPath.row];
        cell.name.text = dict[@"district_name"];
        cell.shijian.text = dict[@"update_time"];
        cell.neirong.text = dict[@"activity_name"];
        [cell.touxiang sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://172.24.10.175/workout/Uploads/%@",dict[@"thumb"]]]];
        [cell.shaitu sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://172.24.10.175/workout/Uploads/%@",dict[@"thumb"]]]];
        
        [cell.pinglunbt addTarget:self action:@selector(pinglun)forControlEvents:UIControlEventTouchUpInside];
    }
    return cell;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return dateArr.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 300;
}
-(void)initwithdate{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager GET:@"http://172.24.10.175/workout/api.php/lists" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        dateArr =responseObject;
        [tableview reloadData];
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
    
}
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    pinglunlbViewController *pinglunlbVC = [[pinglunlbViewController alloc] init];
//    [self.navigationController pushViewController:pinglunlbVC animated:YES];
}

-(void) fabu {
    FabuViewController *fabuVC = [[FabuViewController alloc] init];
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:fabuVC animated:YES];
    self.hidesBottomBarWhenPushed = NO;
}


-(void)pinglun{
    PinglunViewController *pinglunVC = [[PinglunViewController alloc] init];
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:pinglunVC animated:YES];
    self.hidesBottomBarWhenPushed = NO;
}
@end


